﻿using System;
using System.Collections.ObjectModel;
using System.Reflection;

namespace XamlMvp
{
    public class EventFinder
    {
        Collection<EventInfo> events = new Collection<EventInfo>();
        public Type Type { get; private set; }

        public EventFinder(Type type)
        {
            this.Type = type;
        }

        public EventInfo Find(string name)
        {
            var e = Type.GetEvent(name);
            if (e == null)
            {
                foreach(var implemented in Type.GetInterfaces())
                {
                    e = implemented.GetEvent(name);
                    if (e != null) break;
                }
            }
            if (e != null)
            {
                events.Add(e);
            }
            return e;
        }
    }
}
